" -----------------------------------------------------------------------------
"  < 判断操作系统是否是 Windows 还是 Linux >
" -----------------------------------------------------------------------------
let g:iswindows = 0
let g:islinux = 0
if(has("win32") || has("win64") || has("win95") || has("win16"))
    let g:iswindows = 1
else
    let g:islinux = 1
endif " -----------------------------------------------------------------------------
"  < 判断是终端还是 Gvim >
" -----------------------------------------------------------------------------
if has("gui_running")
    let g:isGUI = 1
else
    let g:isGUI = 0
endif
syntax on
set nocompatible                                      "禁用 Vi 兼容模式
filetype off                                          "禁用文件类型侦测
filetype plugin indent on
runtime macros/matchit.vim                            " load vim default plugin
if (g:iswindows && g:isGUI) 
    call plug#begin('$VIM/vimfiles/plug')
else
    call plug#begin('~/.config/nvim/plug')
endif

" Plug 'vim-scripts/indexer.tar.gz'
" Plug 'vim-scripts/DfrankUtil'
" Plug 'vim-scripts/vimprj'
Plug 'itchyny/lightline.vim'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'vim-scripts/a.vim'
" Plug 'vim-scripts/Align.vim'
Plug 'frazrepo/vim-rainbow'
Plug 'jiangmiao/auto-pairs'
Plug 'rstacruz/sparkup', {'rtp': 'vim/'}
Plug 'jlanzarotta/bufexplorer'
Plug 'Yggdroot/indentLine'
Plug 'vim-scripts/Mark--Karkat'
Plug 'scrooloose/nerdcommenter'
Plug 'scrooloose/nerdtree'
Plug 'tpope/vim-surround'
Plug 'majutsushi/tagbar'
" Plug 'vim-airline/vim-airline'
" Plug 'vim-airline/vim-airline-themes'
Plug 'vim-scripts/L9'
Plug 'vim-scripts/DoxygenToolkit.vim'
Plug 'vim-scripts/txt.vim'
" Plug 'rhysd/vim-clang-format'
Plug 'octol/vim-cpp-enhanced-highlight'
Plug 'vim-scripts/mru.vim'
Plug 'mhinz/vim-startify'
Plug 'mileszs/ack.vim'
Plug 'ryanoasis/vim-devicons'
Plug 'godlygeek/tabular'
Plug 'jacoborus/tender.vim'
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
Plug 'trevordmiller/nova-vim'
Plug 'ajmwagar/vim-deus'
" colorscheme
Plug 'arcticicestudio/nord-vim'
call plug#end()

" -----------------------------------------------------------------------------
"  < 编码配置 >
" -----------------------------------------------------------------------------
" 注：使用utf-8格式后，软件与程序源码、文件路径不能有中文，否则报错
set encoding=utf-8                                    "设置gvim内部编码，默认不更改
set fileencoding=utf-8                                "设置当前文件编码，可以更改，如：gbk（同cp936）
set fileencodings=ucs-bom,utf-8,shift-jis,gbk,cp936,latin-1    "设置支持打开的文件的编码
" set fileencodings=ucs-bom,utf-8,gbk,cp936,latin-1    "设置支持打开的文件的编码
" 文件格式，默认 ffs=dos,unix
set fileformat=unix                                   "设置新（当前）文件的<EOL>格式，可以更改，如：dos（windows系统常用）
set fileformats=unix,dos,mac                          "给出文件的<EOL>格式类型
if (g:iswindows && g:isGUI)
    "解决菜单乱码
    source $VIMRUNTIME/delmenu.vim
    source $VIMRUNTIME/menu.vim
    "解决consle输出乱码
    language messages zh_CN.utf-8
endif

" -----------------------------------------------------------------------------
"  < 编写文件时的配置 >
" -----------------------------------------------------------------------------
set hidden
filetype on                                           "启用文件类型侦测
filetype plugin on                                    "针对不同的文件类型加载对应的插件
filetype plugin indent on                             "启用缩进
set smartindent                                       "启用智能对齐方式
set expandtab                                         "将Tab键转换为空格
set tabstop=4                                         "设置Tab键的宽度
set shiftwidth=4                                      "换行时自动缩进4个空格
set smarttab                                          "指定按一次backspace就删除shiftwidth宽度的空格
set backspace=2                                       " 设置退格键可用
set mouse=a                                           " 在任何模式下启用鼠标
" set foldenable                                        "启用折叠
" set foldmethod=indent                                 "indent 折叠方式
" set foldmethod=marker                                 "marker 折叠方式
set ignorecase                                        "搜索模式里忽略大小写
set smartcase                                         "如果搜索模式包含大写字符，不使用 'ignorecase' 选项，只有在输入搜索模式并且打开 'ignorecase' 选项时才会使用
set hlsearch                                          "高亮搜索
set incsearch                                         "在输入要搜索的文字时，实时匹配
" 临时文件
set nobackup
set noundofile
set noswapfile
" 当文件在外部被修改，自动更新该文件
set autoread
" 编辑同一文件时，回到last位置
if has("autocmd")
    au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
" 自动切换目录为当前编辑文件所在目录
au BufRead,BufNewFile,BufEnter * cd %:p:h
" 启用每行超过80列的字符提示（字体变蓝并加下划线），不启用就注释掉
" au BufWinEnter * let w:m2=matchadd('Underlined', '\%>' . 80 . 'v.\+', -1)

" -----------------------------------------------------------------------------
"  < map快捷键 >
" -----------------------------------------------------------------------------
" 注："<Leader>"在本软件中设置为"f"键，如<Leader>t
" 指在常规模式下按"f"键加"t"键，这里不是同时按，而是先按"f"键后按"t"键，间隔在一
" 秒内，而<Leader>cs是先按"f"键再按"c"又再按"s"键,默认的是"\"键，可以修改
let mapleader = "f"         "全局键<leader>,可以修改
" 全屏切换 F11

" 在不使用 MiniBufExplorer 插件时也可用<C-k,j,h,l>切换到上下左右的窗口中去
noremap <c-k> <c-w>k
noremap <c-j> <c-w>j
noremap <c-h> <c-w>h
noremap <c-l> <c-w>l

" Ctrl + K/J/H/L 插入模式下光标向上下左右移动
imap <c-k> <Up>
imap <c-j> <Down>
imap <c-h> <Left>
imap <c-l> <Right>
" 复制粘贴(系统剪切板)
vmap <Leader>y "+y
noremap <Leader>p "+p
" 映射使用explorer打开当前目录
" nmap <tab>e :!start explorer /select,%:p<cr>
" nmap <Tab>e :!nautilus %:p<cr>

" 常规模式下用空格键来开关光标行所在折叠（注：zR 展开所有折叠，zM 关闭所有折叠）
"nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>

" 切换标签
" :tabn或gt  移动到下一个标签页。
" :tabp或gT  移动到上一个标签页。
" :tabe <文件名>  在新标签页中打开指定的文件。
" :tabnew <文件名>  在新标签页中编辑新的文件。
nmap tc :tabc<CR>
nmap tn :tabnew<CR>
" 打开ctags列表
nmap ts :ts<cr>

" 定义快捷键关闭当前分割窗口
nmap <Leader>q :q<CR>
" 定义快捷键保存当前窗口内容
nmap <Leader>w :w<CR>
" 定义快捷键保存所有窗口内容并退出 vim
nmap <Leader>WQ :wa<CR>:q<CR>
" 不做任何保存，直接退出 vim
nmap <Leader>Q :qa!<CR>

" 常规模式下输入 cS 清除行尾空格
" nmap cz :%s/\s\+$//g<CR>:noh<CR>
nmap <F6> :%s/\s\+$//g<CR>:noh<CR>

" 常规模式下输入 cM 清除行尾 ^M 符号
nmap cm :%s/\r$//g<CR>:noh<CR>

" 打开函数列表《tarbar插件》
nmap tb :TagbarToggle<CR>
nmap <F5> :TagbarToggle<CR>

" 打开文件树形结构列表《nerdtree插件》
nmap <F3> :NERDTreeToggle<CR>

" 打开最近编辑文件列表《Mru插件》
nmap <F4> :MRU<cr>

" 头文件源文件跳转《a.vim插件》
nnoremap <silent> <F2> :A<CR> 

" 函数说明模板《DoxygenToolkit插件》
nnoremap <F7> :Dox<cr>

" 开启/关闭对齐线《IndentLine插件》
nmap <leader>il :IndentLinesToggle<CR>

" 文件查找《ctrlp插件》
" 常规模式下输入：Ctrl + f 调用插件
let g:ctrlp_map = '<c-f>'
 
" 给不同的单词高亮，表明不同的变量时很有用《Mark--Karkat插件》
" 快捷键插件内置
" <leader>m 高亮/取消选中的单词
" <leader>n 取消高亮的所有单词
" <leader>/ 查找高亮的所有单词
 
" 代码注释《nerdcommenter插件》
" 下面快捷键插件内置
" <Leader>ci 以每行一个 /* */ 注释选中行(选中区域所在行)，再输入则取消注释
" <Leader>cm 以一个 /* */ 注释选中行(选中区域所在行)，再输入则称重复注释
" <Leader>cc 以每行一个 /* */ 注释选中行或区域，再输入则称重复注释
" <Leader>cu 取消选中区域(行)的注释，选中区域(行)内至少有一个 /* */
" <Leader>ca 在/*...*/与//这两种注释方式中切换（其它语言可能不一样了）
" <Leader>cA 行尾注释
 
" 缓存切换（相当于另一种多个文件间的切换方式）《BufExplorer 插件配置》
" 下面快捷键插件内置
" <Leader>be 在当前窗口显示缓存列表并打开选定文件
" <Leader>bs 水平分割窗口显示缓存列表，并在缓存列表窗口中打开选定文件
" <Leader>bv 垂直分割窗口显示缓存列表，并在缓存列表窗口中打开选定文件
" -----------------------------------------------------------------------------
"  < 界面配置 >
" -----------------------------------------------------------------------------

set number                                            "显示行号
set laststatus=2                                      "启用状态栏信息
set cmdheight=1                                      "设置命令行的高度为2，默认为1
" set cursorline                                        "突出显示当前行
" set guifont=YaHei_Consolas_Hybrid:h10                 "设置字体:字号（字体名称空格用下划线代替）
" set guifont=DejaVu_Sans_Mono:h14
" set guifont=Inconsolata-g_for_Powerline:h14
" set guifont=Hack:h14
" set guifont=Source_Code_Pro_Medium:h18
" set guifont=Source\ Code\ Pro\ Medium\ for\ Powerline\ 16
" set guifont=Droid\ Sans\ Mono\ for\ Powerline\ Nerd\ Font\ Complete\ 12
" set guifont=DroidSansMonoforPowerline\ Nerd\ Font\ 12
" set guifont=SauceCodePro\ Nerd\ Font\ Mono\ 18
if g:isGUI
    " set guifont=DroidSansMonoforPowerline\ Nerd\ Font\ 12
     " set guifont=SauceCodePro_Nerd_Font_Mono:h16
     set guifont=SauceCodePro_NF:h16
endif
set nowrap                                            "设置不自动换行
set shortmess=atI                                     "去掉欢迎界面
" 设置 gVim 窗口初始位置及大小
if g:isGUI
    " au GUIEnter * simalt ~x                         "窗口启动时自动最大化
    winpos 100 10                                     "指定窗口出现的位置，坐标原点在屏幕左上角
    set lines=38 columns=120                          "指定窗口大小，lines为高度，columns为宽度
endif

" 设置代码配色方案
set t_Co=256                                          "在终端启用256色
if g:isGUI
    set background=dark
    colorscheme OceanicNext
    " colorscheme one
    " let g:one_allow_italics = 1 " I love italic for comments
else
    set background=dark
    colorscheme OceanicNext
    " set background=dark
    " set background=light
    " colorscheme one
    " colorscheme deus
    " let g:material_terminal_italics = 1
    " let g:material_theme_style = 'lighter'
    " colorscheme material
    set termguicolors
endif

" 显示/隐藏菜单栏、工具栏、滚动条，可用 Ctrl + F11 切换
if g:isGUI
    set guioptions-=m
    set guioptions-=T
    set guioptions-=r
    set guioptions-=L
    map <silent> <c-F11> :if &guioptions =~# 'm' <Bar>
                \set guioptions-=m <Bar>
                \set guioptions-=T <Bar>
                \set guioptions-=r <Bar>
                \set guioptions-=L <Bar>
                \else <Bar>
                \set guioptions+=m <Bar>
                \set guioptions+=T <Bar>
                \set guioptions+=r <Bar>
                \set guioptions+=L <Bar>
                \endif<CR>
endif

" =============================================================================
"                          << 以下为常用插件配置 >>
" =============================================================================
" -----------------------------------------------------------------------------
"  < startify 插件配置 >
" -----------------------------------------------------------------------------
" 自定义Header和Footer
let g:startify_custom_header = [
    \ '      ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓Hello World▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓',                            
    \ ]
" let g:startify_custom_header = [
    " \ '      ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁    ░▓▓▒         ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁',
    " \ '     ▕                        ▁  ░░▓▓▒▒▒     ▁▔                        ▔▏',
    " \ '    ▕ ▗▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚  ░░░▓▓▓▓▓▒▒▒  ▕ ▗▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▖▒▒',
    " \ '    ▕ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒ ▓▓▓▓▓▓▓▓▓▒▒ ▕ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒',
    " \ '    ▕ ▝▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚ ▒▓▓▓▓▓▓▓▓▓▓▓▒▒▒ ▝▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▀▘▒',
    " \ '     ▕     ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒    ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▏',
    " \ '      ▔▔▔▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒  ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒',
    " \ '         ▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓    ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒',
    " \ '         ▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓    ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒',
    " \ '         ▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓   ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒',
    " \ '         ▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓    ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒',
    " \ '         ▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▓▓▓▓▓▓▓▓▓▓    ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒',
    " \ '         ▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▓▓▓▓▓▓▓▓    ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▒▒',
    " \ '         ▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▓▓▓▓▓▓▓   ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▒▓▓▒▒▒',
    " \ '        ░▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▓▓▓▓▓   ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▓▓▓▓▓▓▒▒▒',
    " \ '       ░░▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▓▓▓    ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▓▓▓▓▓▓▓▓▓▓▒▒▒',
    " \ '     ░░░▓▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▓    ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒',
    " \ '   ░░░▓▓▓▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒    ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒',
    " \ ' ░░░▓▓▓▓▓▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒  ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒',
    " \ '▒▒▒▓▓▓▓▓▓▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒',
    " \ ' ▒▒▒▓▓▓▓▓▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████',
    " \ '   ▒▒▒▓▓▓▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓███',
    " \ '     ▒▒▓▓▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▖▖▖▖▖▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓███',
    " \ '      ▒▒▒▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▚▚▚▚▚▘▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓███',
    " \ '       ▒▒▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒ ▚▚▚▚▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓███',
    " \ '        ▒▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓███',
    " \ '         ▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▚▚▚▚▚▚▚▚▓▓▓▚▚▚▚▚▚▖▓▓▗▚▚▚▚▚▖██ ▗▚▚▚▚▚',
    " \ '         ▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▓▓▓▚▚▚▚▘▓▓▓▓▓▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚',
    " \ '         ▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▓▓▓▓▚▚▚▚▚▎▓▓▓▓▓▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚▚',
    " \ '         ▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▒▓▓▓▓▚▚▚▚▚▎▓▓▓▓▓▚▚▚▚▓▓▓▓▞▚▚▚▚▚      ▚▚▚▚▚',
    " \ '         ▏ ▚▚▚▚▚▚▚▚▚▚▚▚▚▒▒▓▓▓▓▓▚▚▚▚▚▘▓▓▓▓▓▚▚▚▚▚▓▓██▞▚▚▚▚▚     ▚▚▚▚▚',
    " \ '         ▏ ▚▚▚▚▚▚▚▚▚▚▚▒▒▒▒▓▓▓▓▓▚▚▚▚▚▘▓▓▓▓▚▚▚▚▚▓███  ▚▚▚▚      ▚▚▚▚▚',
    " \ '         ▏ ▚▚▚▚▚▚▚▚▚▒▒▒▒▒▒▒▓▓▓▚▚▚▚▞▞▓▓▓▓▓▚▚▚▚▓██   ▚▚▚▚▚     ▚▚▚▚▚',
    " \ '         ▏ ▚▚▚▚▚▚▒▒▒▒    ▒▒▒▒▚▚▚▚▚▚▓▓▓▓▓▚▚▚▚▚██    ▚▚▚▚     ▚▚▚▚▚▚',
    " \ '         ▔▁▀▒▒▒▒▒▒         ▒▒▚▚▚▚▚▚▚▚▓▓▓▚▚▚▚▚▚    ▚▚▚▚▚▚    ▚▚▚▚▚▚▚',
    " \ '           ▔                  ▒▒▓▓▓▓▓▓▓▓███',
    " \ '                               ▒▒▒▓▓▓▓███',
    " \ '                                 ▒▒▒▓██▓',
    " \ '                                   ▒█▓',
    " \ ]

" let g:startify_custom_footer = [
            " \ '+------------------------------+',
            " \ '|                              |',
            " \ '+----------------+-------------+',
            " \]
            "
" -----------------------------------------------------------------------------
"  < coc 插件配置 >
" -----------------------------------------------------------------------------
let g:coc_disable_startup_warning = 1
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

function! s:check_back_space() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1]  =~# '\s'
endfunction

" Use <c-space> to trigger completion.
if has('nvim')
  inoremap <silent><expr> <c-space> coc#refresh()
else
  inoremap <silent><expr> <c-@> coc#refresh()
endif
" -----------------------------------------------------------------------------
"  < clang foramt 插件配置 >
" -----------------------------------------------------------------------------
" let g:clang_format#style_options = {
            " \ "AccessModifierOffset" : -2,
            " \ "AllowShortIfStatementsOnASingleLine" : "true",
            " \ "AlwaysBreakTemplateDeclarations" : "true",
            " \ "Standard" : "C++11"}

" map to <Leader>k in C++ code
" autocmd FileType c,cpp,objc nnoremap <buffer><Leader>k :<C-u>ClangFormat<CR>
" autocmd FileType c,cpp,objc vnoremap <buffer><Leader>k :ClangFormat<CR>
" Toggle auto formatting:
" nmap <Leader>C :ClangFormatAutoToggle<CR>
" -----------------------------------------------------------------------------
"  < YouCompleteMe 插件配置 >
" -----------------------------------------------------------------------------
" ycm编译CXX="/usr/bin/gcc-5" ./install.py --clang-completer
"
let g:ycm_server_python_interpreter="/usr/bin/python"
let g:ycm_global_ycm_extra_conf = "~/.ycm_extra_conf.py"
" 补全功能在注释中同样有效
let g:ycm_complete_in_comments=1
" 允许 vim 加载 .ycm_extra_conf.py 文件，不再提示
let g:ycm_confirm_extra_conf=0
"关闭语法检查"
let g:ycm_enable_diagnostic_signs = 0
let g:ycm_enable_diagnostic_highlighting = 0
set completeopt-=preview
" 从第一个键入字符就开始罗列匹配项
let g:ycm_min_num_of_chars_for_completion=1
" 禁止缓存匹配项，每次都重新生成匹配项
" let g:ycm_cache_omnifunc=0
" 语法关键字补全
let g:ycm_seed_identifiers_with_syntax=1
" 修改对C函数的补全快捷键，默认是CTRL + space，修改为ALT + ;
" let g:ycm_key_invoke_completion = '<C-Space>'
" 基于语义的代码导航
nnoremap <leader>jc :YcmCompleter GoToDeclaration<CR>
" 只能是 #include 或已打开的文件
nnoremap <leader>jd :YcmCompleter GoToDefinition<CR>
" 设置转到定义处的快捷键为ALT + G，这个功能非常赞
nmap <M-g> :YcmCompleter GoToDefinitionElseDeclaration <C-R>=expand("<cword>")<CR><CR>
let g:ycm_show_diagnostics_ui = 0
let g:ycm_allow_changing_updatetime = 1
"回车即选中当前项
inoremap <expr> <CR>       pumvisible() ? "\<C-y>" : "\<CR>"
"let g:ycm_auto_trigger = 0
if g:isGUI
    " YCM 补全菜单配色
    " 菜单
    highlight Pmenu ctermfg=2 ctermbg=3 guifg=#005f87 guibg=#EEE8D5
    " 选中项
    highlight PmenuSel ctermfg=2 ctermbg=3 guifg=#AFD700 guibg=#106900
endif
let g:ycm_semantic_triggers =  {
            \   'c' : ['->', '.'],
            \   'objc' : ['->', '.', 're!\[[_a-zA-Z]+\w*\s', 're!^\s*[^\W\d]\w*\s',
            \             're!\[.*\]\s'],
            \   'ocaml' : ['.', '#'],
            \   'cpp,objcpp' : ['->', '.', '::'],
            \   'perl' : ['->'],
            \   'php' : ['->', '::'],
            \   'cs,java,javascript,typescript,d,python,perl6,scala,vb,elixir,go' : ['.'],
            \   'ruby' : ['.', '::'],
            \   'lua' : ['.', ':'],
            \   'erlang' : [':'],
            \ }

" -----------------------------------------------------------------------------
"  < acp 插件配置 >
" -----------------------------------------------------------------------------
let g:acp_enableAtStartup = 0
" -----------------------------------------------------------------------------
"  < a.vim 插件配置 >
" -----------------------------------------------------------------------------
" 用于切换C/C++头文件
" :A     ---切换头文件并独占整个窗口
" :AV    ---切换头文件并垂直分割窗口
" :AS    ---切换头文件并水平分割窗口

" -----------------------------------------------------------------------------
"  < DoxygenToolkit 插件配置 >
" -----------------------------------------------------------------------------
let g:DoxygenToolkit_briefTag_pre = "@Breif:  "
let g:DoxygenToolkit_paramTag_pre = "@Param:  "
let g:DoxygenToolkit_returnTag = "@Returns:  "
let g:DoxygenToolkit_authorName = "gongqi"
let g:DoxygenToolkit_briefTag_funcName = "yes"
let g:Doxygen_enhanced_color = 1
let g:DoxygenToolkit_endCommentTag = ""
let g:Doxygen_enhanced_blockHeader = "================================================================="
let g:Doxygen_enhanced_blockFooter = "================================================================="
" -----------------------------------------------------------------------------
"  < Align 插件配置 >
" -----------------------------------------------------------------------------
" 一个对齐的插件，对齐代码
" -----------------------------------------------------------------------------
"  < gitgutter 插件配置 >
" -----------------------------------------------------------------------------
let g:gitgutter_max_signs = 1000 
" -----------------------------------------------------------------------------
"  < auto-pairs 插件配置 >
" -----------------------------------------------------------------------------
" 用于括号与引号自动补全
" -----------------------------------------------------------------------------
"  < BufExplorer 插件配置 >
" -----------------------------------------------------------------------------
" 缓存切换（相当于另一种多个文件间的切换方式）
" <Leader>be 在当前窗口显示缓存列表并打开选定文件
" <Leader>bs 水平分割窗口显示缓存列表，并在缓存列表窗口中打开选定文件
" <Leader>bv 垂直分割窗口显示缓存列表，并在缓存列表窗口中打开选定文件
" -----------------------------------------------------------------------------
"  < ctrlp.vim 插件配置 >
" -----------------------------------------------------------------------------
" 一个全路径模糊文件，缓冲区，最近最多使用，... 检索插件；详细帮助见 :h ctrlp
" 常规模式下输入：Ctrl + f 调用插件
let g:ctrlp_cmd = ':CtrlP'
let g:ctrlp_working_path_mode = '0'
" -----------------------------------------------------------------------------
"  < indentLine 插件配置 >
" -----------------------------------------------------------------------------
" 用于显示对齐线，与 indent_guides 在显示方式上不同，根据自己喜好选择了 
" 设置Gvim的对齐线样式
" if g:isGUI
    let g:indentLine_char = "┊"
    let g:indentLine_first_char = "┊"
" endif
" 设置终端对齐线颜色，如果不喜欢可以将其注释掉采用默认颜色
let g:indentLine_color_term = 239
let g:indentLine_enabled = 1
" 设置 GUI 对齐线颜色，如果不喜欢可以将其注释掉采用默认颜色
" let g:indentLine_color_gui = '#A4E57E'
" -----------------------------------------------------------------------------
"  < Mark--Karkat（也就是 Mark） 插件配置 >
" -----------------------------------------------------------------------------
" 给不同的单词高亮，表明不同的变量时很有用，详细帮助见 :h mark.txt
" -----------------------------------------------------------------------------
"  < nerdcommenter 插件配置 >
" -----------------------------------------------------------------------------
" 主要用于C/C++代码注释(其它的也行)
" 以下为插件默认快捷键，其中的说明是以C/C++为例的，其它语言类似
" <Leader>ci 以每行一个 /* */ 注释选中行(选中区域所在行)，再输入则取消注释
" <Leader>cm 以一个 /* */ 注释选中行(选中区域所在行)，再输入则称重复注释
" <Leader>cc 以每行一个 /* */ 注释选中行或区域，再输入则称重复注释
" <Leader>cu 取消选中区域(行)的注释，选中区域(行)内至少有一个 /* */
" <Leader>ca 在/*...*/与//这两种注释方式中切换（其它语言可能不一样了）
" <Leader>cA 行尾注释
let NERDSpaceDelims = 1                     "在左注释符之后，右注释符之前留有空格
" -----------------------------------------------------------------------------
"  < nerdtree 插件配置 >
" -----------------------------------------------------------------------------
" 有目录村结构的文件浏览插件
" 常规模式下输入 F3 调用插件
" -----------------------------------------------------------------------------
"  < omnicppcomplete 插件配置 >
" -----------------------------------------------------------------------------
" 用于C/C++代码补全，这种补全主要针对命名空间、类、结构、共同体等进行补全，详细
" 说明可以参考帮助或网络教程等
" 使用前先执行如下 ctags 命令（本配置中可以直接使用 ccvext 插件来执行以下命令）
" ctags -R --c++-kinds=+p --fields=+iaS --extra=+q
" set completeopt=menu                        "关闭预览窗口
" set completeopt=menu,menuone
" let OmniCpp_MayCompleteDot=1    "打开  . 操作符
" let OmniCpp_MayCompleteArrow=1  "打开 -> 操作符
" let OmniCpp_MayCompleteScope=1  "打开 :: 操作符
" let OmniCpp_NamespaceSearch=1   "打开命名空间
" let OmniCpp_GlobalScopeSearch=1
" let OmniCpp_DefaultNamespace=["std"]
" let OmniCpp_ShowPrototypeInAbbr=1  "打开显示函数原型
" let OmniCpp_SelectFirstItem = 2    "自动弹出时自动跳至第一个
" -----------------------------------------------------------------------------
"  < airline 插件配置 >
" -----------------------------------------------------------------------------
" let g:airline_theme="oceanicnext"
let g:airline_theme="one"
let g:airline_powerline_fonts = 1
"let g:airline_section_b = '%{strftime("%c")}'
"let g:airline_section_y = 'BN: %{bufnr("%")}'
if !exists('g:airline_symbols')
    let g:airline_symbols = {}
endif
  let g:airline_left_sep = ''
  let g:airline_left_alt_sep = ''
  let g:airline_right_sep = ''
  let g:airline_right_alt_sep = ''
  let g:airline_symbols.branch = ''
  let g:airline_symbols.readonly = ''
  let g:airline_symbols.linenr = ''
  let g:airline_symbols.maxlinenr= ''
" -----------------------------------------------------------------------------
"  < lightline 插件配置 >
" -----------------------------------------------------------------------------
let g:lightline = {
      \ 'colorscheme': 'oceanicnext',
      \ }
" -----------------------------------------------------------------------------
"  < octol/vim-cpp-enhanced-highlight 语法高亮 >
" -----------------------------------------------------------------------------
let g:cpp_class_scope_highlight = 1
let g:cpp_member_variable_highlight = 1
let g:cpp_class_decl_highlight = 1
" let g:cpp_experimental_simple_template_highlight = 1
" let g:cpp_experimental_template_highlight = 1
let g:cpp_concepts_highlight = 1
" let g:cpp_no_function_highlight = 1
"解决Vim倾向于将大括号标记为错误的问题
let c_no_curly_error=1
"  < std_c 插件配置 >
" -----------------------------------------------------------------------------
" 用于增强C语法高亮
" 启用 // 注视风格
" let c_cpp_comments = 0
" -----------------------------------------------------------------------------
"  < surround 插件配置 >
" -----------------------------------------------------------------------------
" 快速给单词/句子两边增加符号（包括html标签），缺点是不能用"."来重复命令
" 不过 repeat 插件可以解决这个问题，详细帮助见 :h surround.txt
" -----------------------------------------------------------------------------
"  < Tagbar 插件配置 >
" -----------------------------------------------------------------------------
" 相对 TagList 能更好的支持面向对象
" 常规模式下输入 tb 调用插件，如果有打开 TagList 窗口则先将其关闭
let g:tagbar_width=30                       "设置窗口宽度
let g:tagbar_right=1                         "在左侧窗口中显示
let g:tagbar_autoclose=1
" -----------------------------------------------------------------------------
"  < rainbow 插件配置 >
" -----------------------------------------------------------------------------
" let g:rainbow_active=1
" au FileType c,cpp,objc,objcpp call rainbow#load()
" -----------------------------------------------------------------------------
"  < ZoomWin 插件配置 >
" -----------------------------------------------------------------------------
" 用于分割窗口的最大化与还原
" 常规模式下按快捷键 <c-w>o 在最大化与还原间切换
" =============================================================================
"                          << 以下为常用工具配置 >>
" =============================================================================
" -----------------------------------------------------------------------------
"  < ctags 工具配置 >
" -----------------------------------------------------------------------------
" 对浏览代码非常的方便,可以在函数,变量之间跳转等
set tags+=tags;                            "向上级目录递归查找tags文件
set tags+=~/ex-data/home/gongqi/workspace/desy/FAW-VW-CRS3.0-37W-Soc/FAW-VW-CRS3.0-37W-Core/sva/tags
set tags+=~/ex-data/home/gongqi/workspace/desy/FAW-VW-CRS3.0-37W-Soc/FAW-VW-CRS3.0-37W-Service/svp/tags
"set tags+=./addtags/cpp_stl
"set tags+=./addtags/qt5_cpp
" set tags+=~/03-project/ivali_stable/system/tags
" set tags+=~/03-project/roke-env/system/tags
" set tags+=~/03-project/speed/system/tags
" set tags+=~/03-project/taurus/system/tags

"gtags.vim 设置项
" set cscopetag " 使用 cscope 作为 tags 命令
" set cscopeprg='gtags-cscope' " 使用 gtags-cscope 代替 cscope
" let GtagsCscope_Auto_Load = 1
" let CtagsCscope_Auto_Map = 1
" let GtagsCscope_Quiet = 1
"
" 设置插件 indexer 调用 ctags 的参数
" 默认 --c++-kinds=+p+l，重新设置为 --c++-kinds=+p+l+x+c+d+e+f+g+m+n+s+t+u+v
" 默认 --fields=+iaS 不满足 YCM 要求，需改为 --fields=+iaSl
"ctags -R --c++-kinds=+p --fields=+iaS --extra=+q
" let g:indexer_ctagsCommandLineOptions="--c++-kinds=+p+l+x+c+d+e+f+g+m+n+s+t+u+v --fields=+iaSl --extra=+q --exclude=*test* --exclude=*tst*"
let g:indexer_ctagsJustAppendTagsAtFileSave = 1
map <c-]> g<c-]>
map g] g<c-]>
" nmap <silent> gd <Plug>(coc-definition)
" Use `[g` and `]g` to navigate diagnostics
" nmap <silent> [g <Plug>(coc-diagnostic-prev)
" nmap <silent> ]g <Plug>(coc-diagnostic-next)
" Remap keys for gotos
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
nmap <silent> gc <Plug>(coc-float-hide)
" let b:coc_diagnostic_info = {'error': 0, 'warning': 0, 'information': 0, 'hint':0}
let b:coc_diagnostic_disable = 1
" Remap <C-f> and <C-b> for scroll float windows/popups.
" Note coc#float#scroll works on neovim >= 0.4.0 or vim >= 8.2.0750
" let g:indexer_disableCtagsWarning=1
" let g:indexer_useSedWhenAppend = 1

" -----------------------------------------------------------------------------
"  < gvimfullscreen 工具配置 > 请确保已安装了工具
" -----------------------------------------------------------------------------
" 用于 Windows Gvim 全屏窗口，可用 F11 切换
" 全屏后再隐藏菜单栏、工具栏、滚动条效果更好
if (g:iswindows && g:isGUI)
    map <F11> <Esc>:call libcallnr("gvimfullscreen.dll", "ToggleFullScreen", 0)<CR>
endif

if (g:islinux)
    " map <F11> <Esc>:call system("wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz")<CR>
    " map <F11> <Esc> :call system("wmctrl -ir " . v:windowid . " -b toggle,fullscreen")<CR>
    map <F11> <Esc>:call system("wmctrl -r :ACTIVE: -b toggle,maximized_vert,maximized_horz")<CR>
endif

if (g:iswindows && g:isGUI)
   au GUIEnter * call libcallnr("vimtweak.dll", "SetAlpha", 250)
endif
